﻿using System;
using System.Collections.Generic;
using System.Linq;
using TimeTracker.Models;

namespace TimeTracker.Web.Models
{
    public class EntriesReportModel
    {
        public IEnumerable<EntryModel> Entries { get; set; }

        public IEnumerable<EntriesPerDay> EntriesPerDay
        {
            get
            {
                var grouping = from e in Entries
                               group e by new DateTime(e.LastStartTime.Year, e.LastStartTime.Month, e.LastStartTime.Day, 0, 0, 0)
                               into g
                               select new EntriesPerDay { Date = g.Key.Date, Entries = g };

                return grouping.OrderByDescending(e => e.Date);
            }
        } 
    }
}